package com.sgb.kjwl.view.widget;

import android.content.Context;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.view.ui.adapter.self.CompanyTypeAdapter;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.List;

public class CompanyPopWindow extends BasePopWindow {

    private RecyclerView recyclerView;
    private TextView okView;
    private TextView resetView;
    private LinearLayout bottomLayout;
    private CompanyTypeAdapter companyTypeAdapter;
    private List<String> datas;
    private String type = "";

    public CompanyPopWindow(Context context) {
        super(context, DIR_DOWN_UP);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_company_type;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        recyclerView = holder.getPop().findViewById(R.id.rlv_list);
        bottomLayout = holder.getPop().findViewById(R.id.bottom_layout);
        okView = holder.getPop().findViewById(R.id.ok_view);
        resetView = holder.getPop().findViewById(R.id.reset_view);
        okView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dissMiss();
                if (onResultClick != null) {
                    onResultClick.result(type, null,null);
                    Log.d("公司类型：", type);
                }
            }
        });

        resetView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        companyTypeAdapter = new CompanyTypeAdapter(mContext, null);
        companyTypeAdapter.setItemSelect(true);
        companyTypeAdapter.setDefItem(-1);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.setAdapter(companyTypeAdapter);
        companyTypeAdapter.setOnItemClick(new AdapterOnItemClick<String>() {
            @Override
            public void onItemClick(String s, int position) {
                /*if (no != listParentAreaEntity.getNo() && !"".equals(no)) {
                    childAreaAdapter.resetCheckDatas();
                }
                no = listParentAreaEntity.getNo();
                bottomLayout.setVisibility(View.VISIBLE);
                recyclerView.setAdapter(childAreaAdapter);
                childAreaAdapter.setDatas(listParentAreaEntity.getChildren());*/
                type = s;
            }
        });

    }

    public void setData(List<String> datas) {
        this.datas = datas;
        companyTypeAdapter.setDatas(datas);
    }
}
